<template>
<h1>综合员工列表练习</h1>
  <hr>
  <el-form style="width: 600px;margin: 0 auto;" label-width="80">
    <el-form-item label="姓名">
      <el-input placeholder="请输入用户名" v-model="emp.name"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input placeholder="员工工资" v-model="emp.salary"></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input placeholder="员工岗位" v-model="emp.job"></el-input>
    </el-form-item>

    <el-form-item >
     <el-button type="success" @click="f">提交</el-button>
    </el-form-item>

  </el-form>

  <el-table :data="arr" style="width: 600px;margin: 0 auto;">
    <el-table-column label="编号" type="index" align="center" width="80"></el-table-column>
    <el-table-column label="姓名" prop="name" align="center" ></el-table-column>
    <el-table-column label="工资" prop="salary" align="center" ></el-table-column>
    <el-table-column label="岗位" prop="job" align="center" ></el-table-column>
    <el-table-column  label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>

  </el-table>
</template>
<script setup>
import {ref} from "vue";

const emp=ref({
  name:'',
  salary:'',
  job:''
});
const arr=ref([]);
const f=()=>{
  // if (emp.value.name.trim()=='' || emp.value.salary.trim()==''|| emp.value.job.trim()==''){
  // null undefined '' 0 NaN 只有这五个特殊
  if (!emp.value.name ||!emp.value.name.trim()
      ||!emp.value.salary ||!emp.value.salary.trim()
      || !emp.value.job ||!emp.value.job.trim()){
    alert('请输入数据');
    return;

  }
  arr.value.push(emp.value);
  emp.value={name:'',
    salary:'',
    job:''
  }

};
const del=(index,row)=>{
  if (confirm('删除'+row.name+'?')){
    arr.value.splice(index,1);
  }
};

</script>


<style scoped>

</style>